package com.gold.rabbitmqdemo.study5;

import com.gold.rabbitmqdemo.util.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 发送路由消息-带有routing key
 */
public class RoutingKeyProducer {
    private static final String EXCHANGE_NAME="test_exchange_direct";
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机，type=direct
        channel.exchangeDeclare(EXCHANGE_NAME, "direct");
        String  msg="hello direct!";
        //指定routingKey
        String routingKey="info";
        channel.basicPublish(EXCHANGE_NAME, routingKey, null, msg.getBytes());
        System.out.println("send "+msg);
        channel.close();
        connection.close();
    }
}
